﻿Imports System.Data.SqlClient
Public Class clsDEPARTAMENTOS
    Private cnConn As New SqlConnection
    Private Command As SqlCommand

    Public Sub CONECTA_BD()
        cnConn.ConnectionString = CitraConnection

        Command = New SqlCommand("sp_DEPARTAMENTOS_INSERTA", cnConn)
        Command.CommandType = CommandType.StoredProcedure
        Command.CommandTimeout = 0


        Command.Parameters.Add(New SqlParameter("@CLAVE", SqlDbType.VarChar, 30))
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 200))
        Command.Parameters.Add(New SqlParameter("@CUENTA_COI", SqlDbType.VarChar, 30))
       
        Try
            cnConn.Open()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
    Public Sub GUARDA_DEPARTAMENTO(ByVal CLAVE As String, ByVal NOMBRE As String, ByVal CUENTA As String)
        Command.Parameters("@CLAVE").Value = CLAVE
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters("@CUENTA_COI").Value = CUENTA
       
        Try
            Command.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")

        End Try


    End Sub
    Public Sub ACTUALIZA_DEPTO(ByVal RESPONSABLE As String, ByVal PUESTO As String, ByVal DEPARTAMENTO As String, ByVal SUELDO As Double)
        cnConn.ConnectionString = CitraConnection

        Command = New SqlCommand("sp_DEPARTAMENTO_ACTUALIZA", cnConn)
        Command.CommandType = CommandType.StoredProcedure
        Command.CommandTimeout = 0


        Command.Parameters.Add(New SqlParameter("@RESPONSABLE", SqlDbType.VarChar, 150))
        Command.Parameters.Add(New SqlParameter("@PUESTO", SqlDbType.VarChar, 100))
        Command.Parameters.Add(New SqlParameter("@DEPARTAMENTO", SqlDbType.VarChar, 150))
        Command.Parameters.Add(New SqlParameter("@SUELDO", SqlDbType.Decimal))

        Command.Parameters("@RESPONSABLE").Value = RESPONSABLE
        Command.Parameters("@PUESTO").Value = PUESTO
        Command.Parameters("@DEPARTAMENTO").Value = DEPARTAMENTO
        Command.Parameters("@SUELDO").Value = SUELDO

        Try
            cnConn.Open()
            Command.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


        If cnConn.State = ConnectionState.Open Then
            cnConn.Close()
        End If


    End Sub
    Public Sub Cerrar_BD()
        If cnConn.State = ConnectionState.Open Then
            cnConn.Close()
        End If
    End Sub

End Class
